<?php
/*
**时尚起义手机WEB端
**mm/index.php
**mm.77661.cn
**By QINIAO
*/
require_once('../init.php');

$pageurl = '';
$cid = "10006";      //设定首页默认发布话题ID

if($action == "")
{
$page = isset($_GET['page']) ? abs(intval($_GET['page'])) : 1;
$pageurl .= './index.php?page';

require_once('../model/class.mlog.php');
require_once('../model/class.cates.php');
require_once('../model/class.user.php');

$qiMlog = new qiMlog($DB);
$qiCate = new qiCate($DB);
$qiUser = new qiUser($DB);

$mlogs = $qiMlog->getMlog($page,8);

$virtue = "id";
$setvirtue = "id";
$lognum = $qiMlog->getLogNum($virtue, $setvirtue);

foreach($mlogs as $key=>$val){
$val['cname'] = $qiCate->getCateName($val['cid']);
$val['truename'] = $qiUser->getUserName($val['uid']);
$mlogs[$key] = $val;
}

$page_url = pagination($lognum, 8, $page, $pageurl);

include "view/index.html";
}

if($action == "login")
{

$cookietime = time() + 3600;
$username = isset($_POST['username']) ? trim($_POST['username']) : '';
$password   =isset($_POST['password']) ? md5($_POST['password']) : '';

if(!empty($username)){
 $query="select * from ".DB_PREFIX."users where username='$username'";
 $result=mysql_query($query);
 if(mysql_num_rows($result)<1){
 $notice="<p align=center><font color=red>该用户不存在，请重新登陆！</font></p>";
 }else{
 $info=mysql_fetch_array($result,MYSQL_ASSOC);
 if($info['password']!=$password){
 $notice="<p align=center><font color=red>密码输入错误，请重新登陆！</font></p>";
 }
 else{
	setcookie('username',$username,$cookietime);
	setcookie('password',$password,$cookietime);
    header("Location: index.php");
}
}
}

include "view/login.html";
}

if($action == "logout")
{
header("Content-Typy:text/html; Charset=utf-8");
setcookie('name',time()-1);
setcookie('password',time()-1);
header("Location: index.php");
}

//发布微博
if($action == 'addlog')
{
$logcontent = $_POST['logcontent'];
$aid = $_POST['uploadvalue'];
$ctime = time();
if(empty($logcontent))
{
header("Location: index.php");
}else
{
require_once('../model/class.mlog.php');
$qiMlog = new qiMlog($DB);
$qiMlog->addMlog($cid, $uid, $logcontent,$aid,$ctime);
header("Location: index.php");
}

}

?>